home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / ptpoly_weiler / polygon.h next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  1.2 KB  |  37 lines

  1. #include <stdio.h>
  2.  
  3.     /* polygon vertex definition */
  4. typedef struct vertex_struct {
  5.   double x,y;            /* coordinate values */
  6.   struct vertex_struct    *next;    /* circular singly linked list from poly */
  7.   } vertex, *vertex_ptr;
  8.  
  9.     /* polygon definition */
  10. typedef struct polygon_struct {
  11.   vertex_ptr last;        /* pointer to end of circular vertex list */
  12.   } polygon, *polygon_ptr;
  13.  
  14.     /* return next vertex in polygon list of vertices */
  15. #define polygon_get_vertex(poly, vertex)            \
  16.     ((vertex == NULL) ? poly->last->next : vertex->next)
  17.  
  18.     /* create and insert new polygon vertex */
  19. #define polygon_new_vertex(vertex, poly, xx, yy, new_vertex) {    \
  20.     new_vertex    = (vertex_ptr) malloc (sizeof(vertex));        \
  21.     new_vertex->x = xx;                        \
  22.     new_vertex->y = yy;                        \
  23.     if (poly->last != NULL) {                    \
  24.       new_vertex->next = poly->last->next;            \
  25.       poly->last->next = new_vertex;                \
  26.       }                                \
  27.     else {                            \
  28.       new_vertex->next = new_vertex;                \
  29.       }                                \
  30.     poly->last = new_vertex;                    \
  31.     }
  32.  
  33.     /* create new polygon */
  34. #define polygon_create(poly)                    \
  35.     poly = (polygon_ptr) malloc(sizeof (polygon));        \
  36.     poly->last = NULL;
  37.